﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsTemplateFileBackUp
    {
        public int Add(KeRui.Model.CmsTemplateFileBackUp model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@FileID", SqlDbType.Int, 4), new SqlParameter("@TemplateID", SqlDbType.Int, 4), new SqlParameter("@FileName", SqlDbType.VarChar, 50), new SqlParameter("@FilePath", SqlDbType.VarChar, 500), new SqlParameter("@FileContent", SqlDbType.NText), new SqlParameter("@FileType", SqlDbType.Int, 4), new SqlParameter("@FileUpdateInterval", SqlDbType.Int, 4), new SqlParameter("@UsingNum", SqlDbType.Int, 4), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@IsTop", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@UserName", SqlDbType.NVarChar, 50) };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.FileID;
            parameters[2].Value = model.TemplateID;
            parameters[3].Value = model.FileName;
            parameters[4].Value = model.FilePath;
            parameters[5].Value = model.FileContent;
            parameters[6].Value = model.FileType;
            parameters[7].Value = model.FileUpdateInterval;
            parameters[8].Value = model.UsingNum;
            parameters[9].Value = model.UpdateTime;
            parameters[10].Value = model.IsTop;
            parameters[11].Value = model.UserID;
            parameters[12].Value = model.UserName;
            DbHelperSQL.RunProcedure("CmsTemplateFileBackUp_ADD", parameters, out num);
            return (int) parameters[0].Value;
        }

        public void Delete(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            DbHelperSQL.RunProcedure("CmsTemplateFileBackUp_Delete", parameters, out num);
        }

        public KeRui.Model.CmsTemplateFileBackUp GetModel(int ID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            KeRui.Model.CmsTemplateFileBackUp up = new KeRui.Model.CmsTemplateFileBackUp();
            DataSet set = DbHelperSQL.RunProcedure("CmsTemplateFileBackUp_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    up.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString());
                }
                if (set.Tables[0].Rows[0]["FileID"].ToString() != "")
                {
                    up.FileID = int.Parse(set.Tables[0].Rows[0]["FileID"].ToString());
                }
                if (set.Tables[0].Rows[0]["TemplateID"].ToString() != "")
                {
                    up.TemplateID = int.Parse(set.Tables[0].Rows[0]["TemplateID"].ToString());
                }
                up.FileName = set.Tables[0].Rows[0]["FileName"].ToString();
                up.FilePath = set.Tables[0].Rows[0]["FilePath"].ToString();
                up.FileContent = set.Tables[0].Rows[0]["FileContent"].ToString();
                if (set.Tables[0].Rows[0]["FileType"].ToString() != "")
                {
                    up.FileType = int.Parse(set.Tables[0].Rows[0]["FileType"].ToString());
                }
                if (set.Tables[0].Rows[0]["FileUpdateInterval"].ToString() != "")
                {
                    up.FileUpdateInterval = int.Parse(set.Tables[0].Rows[0]["FileUpdateInterval"].ToString());
                }
                if (set.Tables[0].Rows[0]["UsingNum"].ToString() != "")
                {
                    up.UsingNum = int.Parse(set.Tables[0].Rows[0]["UsingNum"].ToString());
                }
                if (set.Tables[0].Rows[0]["UpdateTime"].ToString() != "")
                {
                    up.UpdateTime = DateTime.Parse(set.Tables[0].Rows[0]["UpdateTime"].ToString());
                }
                if (set.Tables[0].Rows[0]["IsTop"].ToString() != "")
                {
                    up.IsTop = int.Parse(set.Tables[0].Rows[0]["IsTop"].ToString());
                }
                if (set.Tables[0].Rows[0]["UserID"].ToString() != "")
                {
                    up.UserID = int.Parse(set.Tables[0].Rows[0]["UserID"].ToString());
                }
                up.UserName = set.Tables[0].Rows[0]["UserName"].ToString();
                return up;
            }
            return null;
        }

        public void Update(KeRui.Model.CmsTemplateFileBackUp model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@FileID", SqlDbType.Int, 4), new SqlParameter("@TemplateID", SqlDbType.Int, 4), new SqlParameter("@FileName", SqlDbType.VarChar, 50), new SqlParameter("@FilePath", SqlDbType.VarChar, 500), new SqlParameter("@FileContent", SqlDbType.NText), new SqlParameter("@FileType", SqlDbType.Int, 4), new SqlParameter("@FileUpdateInterval", SqlDbType.Int, 4), new SqlParameter("@UsingNum", SqlDbType.Int, 4), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@IsTop", SqlDbType.Int, 4), new SqlParameter("@UserID", SqlDbType.Int, 4), new SqlParameter("@UserName", SqlDbType.NVarChar, 50) };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.FileID;
            parameters[2].Value = model.TemplateID;
            parameters[3].Value = model.FileName;
            parameters[4].Value = model.FilePath;
            parameters[5].Value = model.FileContent;
            parameters[6].Value = model.FileType;
            parameters[7].Value = model.FileUpdateInterval;
            parameters[8].Value = model.UsingNum;
            parameters[9].Value = model.UpdateTime;
            parameters[10].Value = model.IsTop;
            parameters[11].Value = model.UserID;
            parameters[12].Value = model.UserName;
            DbHelperSQL.RunProcedure("CmsTemplateFileBackUp_Update", parameters, out num);
        }
    }
}

